<template>
  <view class="content">
    <img :src="fileSvg" alt="" class="img" @click="clickHandel" v-if="fileType === 1">
    <web-view v-else :src="src"></web-view>
  </view>
</template>

<script>
import { getFile, markEdit, unMarkEdit } from '@/api/api'
import { getToken } from '@/utils/auth'
export default {
  data() {
    return {
      fileSvg: '',
      fileId: '',
      isBack: false,
      fileData: "",
      fileType: 0,
      src: ""
    };
  },
  onLoad(e) {
    console.log(e)
    this.fileId = e.fileId
    getFile(e.fileId).then(res => {
      if (res.data.type == 1) {
        this.fileType = 1
        this.fileSvg = 'data:image/svg+xml;base64,' + res.data.svg
      } else {
        const token = getToken()
        this.src = `https://eaop.cdhongyi.com.cn/mindmap/#/?fileId=${e.fileId}&token=${token}`
        console.log(this.src)
      }
    })
  },
  onShow() {
    getFile(this.fileId).then(res => {
      this.fileSvg = 'data:image/svg+xml;base64,' + res.data.svg
    })
    if (this.isBack) {
      unMarkEdit(this.fileId).then(res => {

      })
    }
  },
  onHide() {
    this.isBack = true
  },
  methods: {
    clickHandel() {
      uni.navigateTo({
        url: `/pages/index/edit/edit?fileId=${this.fileId}`,
      });
      markEdit(this.fileId).then(res => {
        console.log(res)
      })
    },
  },
}
</script>

<style lang="scss">
.content {
  width: 100vw;
  height: 100vh;

  .img {
    width: 100%;
    height: 100%;
  }
}
</style>
